/**
 * 
 */
package sudoku.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import sudoku.util.BrowserControl;
import sudoku.util.Language;

/**
 * @author rometp
 *
 */
public class NotifyUI implements MouseListener{
	
	private volatile Language language;
	
	private JLabel link;
	private JDialog dialog;
	
	/**
	 * Teeb mängu abi akna.
	 * @param language keele klassi isend
	 */
	public NotifyUI(Language language){
		this.language = language;
		
		drawWindow();
	}
	
	public void drawWindow() {
		dialog = new JDialog();
		dialog.setTitle(language.getMessage());
		dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		JPanel panel = new JPanel(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		int i = 0;
		String[] s = language.getMain_version3().split("\n");
		for (; i < s.length; i++) {
			c.gridx = 0;
			c.gridy = i;
			c.anchor = GridBagConstraints.LINE_START;
			JLabel label = new JLabel(s[i]);
			if (s[i].startsWith(" http")) {
				link = label;
				link.setForeground(Color.BLUE);
				link.addMouseListener(this);
				panel.add(link, c);
			}
			else
				panel.add(label, c);
		}
		dialog.add(panel, BorderLayout.CENTER);
		dialog.pack();
		dialog.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-dialog.getWidth(), Toolkit.getDefaultToolkit().getScreenSize().height/2-dialog.getHeight());
		dialog.setVisible(true);
	}

	public void mouseClicked(MouseEvent e) {
		BrowserControl.displayURL(link.getText().substring(1));
		dialog.dispose();
	}

	public void mouseEntered(MouseEvent e) {
		dialog.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	}

	public void mouseExited(MouseEvent e) {
		dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
	}

	public void mousePressed(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}
}
